package com.lemon.boot.controller;

import cn.hutool.core.lang.Dict;
import com.lemon.boot.common.annotation.NotAuthorization;
import com.lemon.boot.common.annotation.ResponseNotResult;
import com.lemon.boot.common.web.Result;
import com.lemon.boot.dto.InviteDTO;
import com.lemon.boot.dto.UpdatePasswordDTO;
import com.lemon.boot.dto.UserDTO;
import com.lemon.boot.po.NoticePO;
import com.lemon.boot.service.IWelcomeService;
import com.lemon.boot.vo.RouteResourceVO;
import com.lemon.boot.vo.RouteVO;
import com.lemon.boot.vo.WelcomeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import java.util.List;
import java.util.Map;

/**
 * @author 李猛
 * @datetime 2024/5/18 17:26
 * @description 类对象
 */
@Log4j2
@Api(tags = "欢迎页")
@RestController
@RequestMapping("welcome")
public class WelcomeController {
    @Resource
    private IWelcomeService iWelcomeService;

    /**
     * 获取API
     *
     * @return
     */
    @PermitAll
    @ApiOperation(value = "获取API")
    @GetMapping("getApi")
    public Map<String, Object> getApi() {
        return iWelcomeService.getApi();
    }

    /**
     * 欢迎页-查询当前用户信息
     *
     * @return
     */
    @PermitAll
    @ApiOperation(value = "欢迎页-查询当前用户信息")
    @GetMapping("getByCurrentUser")
    public WelcomeVO getByCurrentUser() {
        return iWelcomeService.getByCurrentUser();
    }

    /**
     * 查询当前用户的头像
     *
     * @return
     */
    @PermitAll
    @ApiOperation(value = "查询当前用户的头像")
    @GetMapping("getCurrentAvatar")
    public Result<String> getCurrentAvatar() {
        return iWelcomeService.getCurrentAvatar();
    }

    /**
     * 查询当前用户的公司名称
     *
     * @return
     */
    @PermitAll
    @ApiOperation(value = "查询当前用户的公司名称")
    @GetMapping("getCurrentTenantName")
    public Result<String> getCurrentTenantName() {
        return iWelcomeService.getCurrentTenantName();
    }

    /**
     * 修改密码
     *
     * @return
     */
    @PermitAll
    @ApiOperation(value = "修改密码")
    @PutMapping("updatePwd")
    public String updatePwd(@RequestBody Map<String, String> param) {
        return iWelcomeService.updatePwd(param);
    }

    /**
     * 获取路由资源
     *
     * @return
     */
    @PermitAll
    @ApiOperation(value = "获取路由资源")
    @GetMapping("getRouteResource")
    public List<RouteResourceVO> getRouteResource() {
        return iWelcomeService.getRouteResource();
    }

    /**
     * 查询路由
     *
     * @return
     */
    @PermitAll
    @ApiOperation(value = "查询路由")
    @GetMapping("getRoutes")
    public List<RouteVO> getRoutes() {
        return iWelcomeService.getRoutes();
    }

    /**
     * 获取邀请码
     *
     * @return
     */
    @PreAuthorize("hasAnyRole('ROLE_ADMIN','ROLE_SUPER')")
    @ApiOperation(value = "获取邀请码")
    @PostMapping("inviteUser")
    public String inviteUser(@RequestBody InviteDTO inviteDTO) {
        return iWelcomeService.inviteUser(inviteDTO);
    }

    /**
     * 获取邀请时间选择
     *
     * @return
     */
    @PreAuthorize("hasAnyRole('ROLE_ADMIN','ROLE_SUPER')")
    @ApiOperation(value = "获取邀请时间选择")
    @GetMapping("getInviteUserTime")
    public List<Dict> getInviteUserTime() {
        return iWelcomeService.getInviteUserTime();
    }

    /**
     * 租户注册
     *
     * @return
     */
    @PermitAll
    @NotAuthorization
    @ApiOperation(value = "租户注册")
    @PutMapping("tenantRegister")
    public String tenantRegister(@RequestBody Map<String, Object> map) {
        return iWelcomeService.tenantRegister(map);
    }

    /**
     * 用户注册
     *
     * @return
     */
    @PermitAll
    @NotAuthorization
    @ApiOperation(value = "用户注册")
    @PutMapping("userRegister")
    public String userRegister(@RequestBody UserDTO userDTO) {
        return iWelcomeService.userRegister(userDTO);
    }

    /**
     * 获取验证码
     */
    @PermitAll
    @NotAuthorization(enable = true, times = 10)
    @ApiOperation(value = "登录-获取验证码")
    @GetMapping("getCaptchaCode")
    public void getCaptchaCode() {
        iWelcomeService.getCaptchaCode();
    }

    /**
     * 忘记密码-根据邮箱或手机号获取验证码
     */
    @PermitAll
    @NotAuthorization(enable = true, times = 1, timeout = 1)
    @ResponseNotResult
    @ApiOperation(value = "忘记密码-根据邮箱或手机号获取验证码")
    @PostMapping("sendByEmailOrPhone")
    public Dict sendByEmailOrPhone(@RequestBody Map<String, String> param) {
        return iWelcomeService.sendByEmailOrPhone(param);
    }

    /**
     * 修改密码-根据邮箱或手机号修改密码
     *
     * @return
     */
    @PermitAll
    @NotAuthorization
    @ApiOperation(value = "修改密码-根据邮箱或手机号修改密码")
    @PutMapping("updatePwdByEmailOrPhone")
    public Result<String> updatePwdByEmailOrPhone(@RequestBody UpdatePasswordDTO updatePasswordDTO) {
        return iWelcomeService.updatePwdByEmailOrPhone(updatePasswordDTO);
    }

    /**
     * 群发消息
     *
     * @param noticePO
     * @return
     */
    @ApiOperation(value = "群发消息")
    @PostMapping("addNotice")
    public String addNotice(@RequestBody NoticePO noticePO) {
        return iWelcomeService.addNotice(noticePO);
    }

    /**
     * 根据ID查询消息提醒
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "根据ID查询提醒")
    @GetMapping("getNoticeById/{id}")
    public NoticePO getNoticeById(@PathVariable("id") Long id) {
        return iWelcomeService.getNoticeById(id);
    }

    /**
     * 查询提醒集合
     *
     * @param map
     * @return
     */
    @ApiOperation(value = "查询提醒集合")
    @GetMapping("getNoticeList")
    public List<NoticePO> getNoticeList(@RequestParam Map<String, Object> map) {
        return iWelcomeService.getNoticeList(map);
    }

    /**
     * 获取当前用户的个人资料
     *
     * @return
     */
    @PermitAll
    @ApiOperation(value = "获取当前用户的个人资料")
    @GetMapping("getByCurrent")
    public Map<String, Object> getByCurrent() {
        return iWelcomeService.getByCurrent();
    }
}
